package com.wanxi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.ImageService;
import com.wanxi.vo.ImageVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
 * @author Chengbo Zhang
 */
@RestController
@RequestMapping("/admin/image")
@CrossOrigin(origins = "http://localhost:8081")
public class ImageController {
    @Autowired
    ImageService imageService;

    @PutMapping("/add")
    @PreAuthorize("hasAuthority('insertImage')")
    public ResultDTO addImage(ImageVO imageVO){
        return imageService.addImage(imageVO);
    }

    @DeleteMapping("/delete")
    @PreAuthorize("hasAuthority('deleteImage')")
    public ResultDTO deleteImage(ImageVO imageVO){
        return imageService.deleteImage(imageVO);
    }

    @GetMapping("/findAll")
    public ResultDTO deleteImage(){
        return imageService.findAllImage();
    }

    @PostMapping("/findById")
    public ResultDTO findImageById(ImageVO imageVO){
        return imageService.findImageById(imageVO);
    }

    @PostMapping("/updateEnable")
    @PreAuthorize("hasAuthority('updateImage')")
    public ResultDTO updateImageEnable(ImageVO imageVO){
        return imageService.updateEnable(imageVO);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('updateImage')")
    public ResultDTO updateImage(ImageVO imageVO){
        return imageService.update(imageVO);
    }
}
